package leetcode;

/**
 * Created with IntelliJ IDEA.
 * Description:26. 删除有序数组中的重复项
 * User: 东莞呵呵
 * Date:2022-07-06
 * Time:22:22
 */
public class TestDemo3 {
    public static void main(String[] args) {
        int[] nums={1,2,2,2,3,3,4,4,5,5,5,6,6,8};
        int count=removeDuplicates(nums);
        for (int i = 0; i < count; i++) {
            System.out.print(nums[i]+" ");
        }
    }
    public static int removeDuplicates(int[] nums) {
        int i=0;
        int j=1;
        while(j<nums.length)
        if(nums[i]==nums[j]){
            j++;
        }else if(nums[i]<nums[j]){
            nums[i+1]=nums[j];
            i++;
            j=i+1;
        }else{
            j++;
        }
        return i+1;
    }
}
